package com.summer.ASM;

import javassist.ClassPool;
import javassist.CtClass;
import javassist.CtMethod;
import javassist.CtNewMethod;

public class MyJavassistGenerator {
	public static void main(String[] args) throws Exception {  
        ClassPool pool = ClassPool.getDefault();  
        //创建Programmer类       
        CtClass cc= pool.makeClass("com.samples.Programmer");  
        //定义code方法  
        CtMethod method = CtNewMethod.make("public void code(){}", cc);  
        //插入方法代码  
        method.insertBefore("System.out.println(\"I'm a Programmer,Just Coding.....\");");  
        method.insertBefore("System.out.println(\"MyJavassistGenerator\");");  
        cc.addMethod(method);  
        //保存生成的字节码  
        cc.writeFile("C://summer");  
    }  
}
